function shuffle(arr) {
  // let temp = [...arr];
  let temp = arr.slice();
  return function(n) {
    const res = [];
    for (let i = 0; i < n; i++) {
      if (temp.length === 0) {
        temp = [...arr];
      }
      let randomIndex = Math.floor(Math.random() * temp.length);
      [temp[0], temp[randomIndex]] = [temp[randomIndex], temp[0]];
      res.push(temp.shift());
    }
    return res;
  }
}

const arr = [0,1,2,3,4,5]
let randomfn = shuffle(arr);
console.log(randomfn(4));
console.log(randomfn(5));